/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Connections;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author BachDEV
 */
public class DBConnection {
    public static Connection getConnection(String dataSourceName,String username,String password) throws Exception{
        Connection connect = null;
        try{
            String url = "jdbc:sqlserver://localhost:1433;databaseName=BugReportingSystem;username=sa;password=123";
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            connect = DriverManager.getConnection(url);
        }
        catch(Exception ex){
            throw ex;
        }
        return connect;
    }

    public static void closeConnection(Connection connect,PreparedStatement stmt,ResultSet rs) throws Exception{
        try{
            if(rs!=null){
                rs.close();
            }
            if(stmt!=null){
                stmt.close();
            }
            if(connect!=null){
                connect.close();
            }
        }
        catch(Exception ex){
            throw ex;
        }
    }

}
